<template>
  <div>
    <a-tabs v-model:activeKey="tab_activeKey" @change="tab_change">
      <a-tab-pane key="1" tab="机房管理">
        <a-row>
          <a-col :span="20">
            <a-space>
                <div>
                  <span>机房编号:</span>
                  <a-input v-model:value="machine_room_qs.jfbm"  size="small" style="width: 150px;"/> 
                </div>
                <div>
                  <span>编号2:</span>
                  <a-input v-model:value="machine_room_qs.jfbm2"  size="small" style="width: 150px;"/> 
                </div>
                <div>
                  <span>机房名称:</span>
                  <a-input v-model:value="machine_room_qs.name"  size="small" style="width: 150px;"/> 
                </div>
                <div>
                  <span>机房性质:</span>
                  <a-select 
                  v-model:value="machine_room_qs.xz"
                  style="width: 150px;"
                  :options="$store.state.machine_room_xz"
                  size="small"
                  :field-names="{ label: 'name', value: 'val' }"
                  allowClear
                  @change="machine_room_xz_change"
                  >
                  </a-select>
                </div>
            </a-space>
          </a-col>
          <a-col :span="4">
            <a-space>
              <div>
                  <a-button @click="add_machine_room" style="margin: 0 auto;"  v-if="select_room_levels?.length==4 && select_room_levels[1]===true">添加机房</a-button>
              </div>
              <div>
                  <a-button @click="search_machine_room" style="margin: 0 auto;">查询</a-button>
              </div>
            </a-space>
          </a-col>
        </a-row>
        <a-row>
          <a-table 
          :data-source="machine_room_data" 
          :columns="machine_room_columns" 
          class="task-table"
          size="small" 
          :showHeader="true" 
          tableLayout="fixed"
          :pagination="machine_room_pagination" 
          @change="machine_room_pagination_change"
          :customRow="machine_room_event"
          bordered 
          rowKey="_id">
            <template #expandedRowRender="{ record }">
              <a-layout-content style="margin: 10px;">
                <a-descriptions title="实施人信息" bordered class="overflow-descriptions" style="overflow: auto;height: 400px;">
                  <a-descriptions-item label="部门具体实施人" :span="3">{{ record?.bmssr }}</a-descriptions-item>
                  <a-descriptions-item label="部门联系人" :span="3">{{ record.bmlxr }}</a-descriptions-item>
                  <a-descriptions-item label="联系人电话" :span="3">{{ record.bmlxrphone }}</a-descriptions-item>
                  <a-descriptions-item label="拓扑图" :span="3">{{ record.ttt }}</a-descriptions-item>
                  <a-descriptions-item label="普查日期" :span="3">{{ record.time }}</a-descriptions-item>
                  <a-descriptions-item label="等保需求" :span="3">{{ record.dbxq }}</a-descriptions-item>
                  <a-descriptions-item label="等保状态" :span="3">{{ record.dbzt }}</a-descriptions-item>
                  <a-descriptions-item label="备注" :span="3">{{ record.bz }}</a-descriptions-item>
                </a-descriptions>
              </a-layout-content>
            </template>
            <template #bodyCell="{ text, record, index, column }">
              <template v-if="column.dataIndex === 'status'">
                <a-badge :status="record?.status" />
              </template>
                <template v-if="column.dataIndex === 'operation'">
                <span class="table-operation">
                    <a-dropdown>
                    <a class="ant-dropdown-link" @click.prevent>编辑<DownOutlined /></a>
                    <template #overlay>
                        <a-menu>
                          <!-- select_room_levels?.length==4 && select_room_levels[1]===true -->
                          <a-menu-item  v-if="check_machine_room_qx(record,2)">
                              <a href="javascript:;" @click="edit_machine_room(record)">机房编辑</a>
                            </a-menu-item>
                            <a-menu-item  v-if="check_machine_room_qx(record,1)">
                              <a href="javascript:;" @click="edit_machine_room_person(record)" >人员管理</a>
                            </a-menu-item>
                            <a-menu-item >
                              <a href="javascript:;" @click="show_machine_room_tp(record)">实时拓扑</a>
                            </a-menu-item>
                        </a-menu>
                    </template>
                    </a-dropdown>
                </span>
                </template> 
            </template>
            <template #summary>
            <a-table-summary-row>
              <a-table-summary-cell><div style="text-align: center;">小计</div></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <a-table-summary-cell><div style="color:#2db7f5;text-align: center;">{{ machine_room_machine_count }}</div></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <!-- <a-typography-text type="danger">{{ machine_data_sysy }}</a-typography-text> -->
              <a-table-summary-cell></a-table-summary-cell>
            </a-table-summary-row>
          </template>
          </a-table>
        </a-row>
      </a-tab-pane>
      <a-tab-pane key="2" tab="设备管理" v-if="show_machine">
        <a-row>
          <a-col :span="18">
            <a-space>
                <div>
                  <span>机房编号:</span>
                  <a-input  v-model:value="machine_qs.jfbm"  size="small" style="width: 60px;" allowClear @change="machine_jfbm_change"/> 
                </div>
                <div>
                  <span>编号2:</span>
                  <a-input  v-model:value="machine_qs.jfbm2"  size="small" style="width: 60px;" allowClear @change="machine_jfbm2_change"/> 
                </div>
                <!-- <div>
                  <span>设备名称:</span>
                  <a-input  v-model:value="machine_qs.name"  size="small" style="width: 120px;"/> 
                </div> -->
                <div>
                  <span>设备别名:</span>
                  <a-input  v-model:value="machine_qs.aname"  size="small" style="width: 120px;"/> 
                </div>
                <div>
                  <span>设备编号:</span>
                  <a-input  v-model:value="machine_qs.bh"  size="small" style="width: 120px;"/> 
                </div>
                <!-- <div>
                  <span>设备位置:</span>
                  <a-input  v-model:value="machine_qs.wz"  size="small" style="width: 120px;"/> 
                </div> -->
                <div>
                  <span>设备类型:</span>
                  <a-select 
                  v-model:value="machine_qs.type"
                  style="width: 100px;"
                  :options="$store.state.machine_type"
                  size="small"
                  :field-names="{ label: 'name', value: 'val' }"
                  allowClear
                  @change="machine_type_change"
                  >
                  </a-select>
                </div>
                <div>
                  <span>设备状态:</span>
                  <a-select 
                    v-model:value="machine_qs.status"
                    style="width: 100px;"
                    :options="$store.state.machine_status"
                    size="small"
                    :field-names="{ label: 'name', value: 'val' }"
                    allowClear
                    @change="machine_status_change"
                    >
                  </a-select>
                </div>
            </a-space>
          </a-col>
          <a-col :span="6">
            <a-space>
              <a-button @click="clear_machine" style="margin: 0 auto;" v-if="select_room_levels?.length==4 && select_room_levels[2]===true">清空</a-button>
              <a-button @click="add_machine" style="margin: 0 auto;" v-if="select_room_levels?.length==4 && select_room_levels[2]===true">添加设备</a-button>
              <a-button @click="badd_machine" style="margin: 0 auto;" v-if="select_room_levels?.length==4 && select_room_levels[2]===true">导入EXCLE</a-button>
              <a-button @click="search_machine" style="margin: 0 auto;" v-if="select_room_levels?.length==4 && select_room_levels[3]===true">查询设备</a-button>
            </a-space>
          </a-col>
          <input type="file" ref="excle_input" id="excle_input"  style="display: none;" @change="get_excle">
        </a-row>
        <a-row style="max-height: 700px;overflow-y: scroll;">
          <a-table 
          :data-source="machine_data" 
          :columns="machine_columns" 
          class="task-table"
          size="small" 
          :showHeader="true" 
          tableLayout="fixed"
          :pagination="machine_pagination" 
          @change="machine_pagination_change"
          bordered 
          rowKey="_id">
          <template #expandedRowRender="{ record }">
            <a-layout-content style="margin: 10px;">
              <a-tabs v-model:activeKey="machine_tab_activeKey">
                <a-tab-pane key="11" tab="额外信息">
                  <a-descriptions title="设备信息" bordered class="overflow-descriptions" style="overflow: auto;height: 400px;" :column="6">
                    <a-descriptions-item label="机柜位置">{{ record?.wz }}</a-descriptions-item>
                    <a-descriptions-item label="品牌" >{{ record.pp }}</a-descriptions-item>
                    <a-descriptions-item label="型号" >{{ record.xh }}</a-descriptions-item>
                    <a-descriptions-item label="序列号" >{{ record.xlh }}</a-descriptions-item>
                    <a-descriptions-item label="入库时间" >{{ record.sj }}</a-descriptions-item>
                    <a-descriptions-item label="设备用途" >{{ record.yt }}</a-descriptions-item>
                    <a-descriptions-item label="操作系统类型" >{{ record.op }}</a-descriptions-item>
                    <a-descriptions-item label="存储容量" >{{ record.cc }}</a-descriptions-item>
                    <a-descriptions-item label="存储使用量" >{{ record.ccsy }}</a-descriptions-item>
                    <a-descriptions-item label="其他说明" >{{ record.sm }}</a-descriptions-item>
                    <!-- :span="3" -->
                  </a-descriptions>
                </a-tab-pane>
                <a-tab-pane key="12" tab="网络信息">
                  <a-table 
                    :data-source="record?.nets" 
                    :columns="net_columns" 
                    class="task-table"
                    size="small" 
                    :showHeader="true" 
                    tableLayout="fixed"
                    bordered 
                    rowKey="net">
                    </a-table>
                </a-tab-pane>
              </a-tabs>
            </a-layout-content>
          </template>
          <template #bodyCell="{ text, record, index, column }">
            <template v-if="column.dataIndex === 'sysy'">
              {{ record?.sysy }}
            </template>
            <template v-if="column.dataIndex === 'type'">
              {{ $common_apis.get_machine_type_by_Tnum(record?.type)}}
            </template>
            <template v-if="column.dataIndex === 'operation'">
              <span class="table-operation">
                  <a-dropdown>
                  <a class="ant-dropdown-link" @click.prevent>编辑<DownOutlined /></a>
                  <template #overlay>
                      <a-menu>
                        <!-- <a-menu-item>
                            <a href="javascript:;" @click="show_fenbu(record)">机房编辑</a>
                          </a-menu-item> -->
                          <!-- select_room_levels?.length==4 && select_room_levels[2]===true -->
                          <!-- select_room_levels?.length==4 && select_room_levels[1]===true -->
                          <a-menu-item  v-if="check_machine_room_qx(record,2)">
                            <a href="javascript:;" @click="edit_machine(record)">设备管理</a>
                          </a-menu-item>
                          <a-menu-item  v-if="check_machine_room_qx(record,1)">
                            <a-popconfirm 
                              title="确定删除此设备吗?"
                              ok-text="确定"
                              cancel-text="取消"
                              @confirm="delete_machine(record)"
                              >
                              <a href="javascript:;">设备删除</a>
                            </a-popconfirm>
                          </a-menu-item>  
                      </a-menu>
                  </template>
                  </a-dropdown>
              </span>
            </template> 
          </template>
          <template #summary>
            <a-table-summary-row>
              <a-table-summary-cell><div style="text-align: center;">小计</div></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <a-table-summary-cell></a-table-summary-cell>
              <a-table-summary-cell><div style="color:#2db7f5;text-align: center;">{{ machine_data_sysy }}</div></a-table-summary-cell>
              <!-- <a-typography-text type="danger">{{ machine_data_sysy }}</a-typography-text> -->
              <a-table-summary-cell></a-table-summary-cell>
            </a-table-summary-row>
          </template>
        </a-table>
        <!-- <a-alert message="区域网模式有效,将在预处理完成后进行人工选点" banner type="info"/> -->
        </a-row>
      </a-tab-pane>

      <a-tab-pane key="3" tab="统计" v-if="show_machine">
        //统计存储使用量 总的  机房分开的
        //统计设备数量   总的   机房的 还可用的位置
        //
      </a-tab-pane>
    </a-tabs>
    <add_machine></add_machine>
    <edit_machine_rome_person></edit_machine_rome_person>
    <add_machine_rome></add_machine_rome>
    <badd_machine></badd_machine>

    
  </div>
</template>
<script>
import { defineAsyncComponent } from 'vue'
export default {
  data() {
    return {
      role_id:"2c93808288fb4c08018c2435be514325",
      tab_activeKey:"1",
      machine_room_qs:{
        jfbm:"",
        jfbm2:"",
        name:"",
        xz:"",
      },
      machine_room_data:[],
      machine_room_machine_count:0,
      machine_room_columns: [
        {
          title: '机房编号',
          dataIndex: 'jfbm',
          align: 'center',
          width: '80px',
        },
        {
          title: '编号2',
          dataIndex: 'jfbm2',
          align: 'center',
          width: '80px',
        },
        {
          title: '机房名称',
          dataIndex: 'name',
          align: 'center',
          width: '210px',
          ellipsis: true,
        },
        {
          title: '座落',
          dataIndex: 'zl',
          align: 'center',
          // width: '100px',
          ellipsis: true,
        },
        {
          title: '管理部门',
          dataIndex: 'bm',
          align: 'center',
          width: '170px',
          ellipsis: true,
        },
        {
          title: '部门负责人',
          dataIndex: 'bmfzr',
          align: 'center',
          width: '140px',
        },
       

        {
            title: '机房性质',
            dataIndex: 'xz',
            align: 'center',
            width: '140px',
        },
        {
            title: '设备数量',
            dataIndex: 'num',
            align: 'center',
            width: '100px',
        },
        {
          title: '状态',
          dataIndex: 'status',
          align: 'center',
          width: '60px',
        },
        {
            title: '操作',
            width: 80,
            dataIndex: 'operation',
            align: 'center'
        },

        // 
      ],
      machine_room_pagination: {
        current: 1,
        size: 'small',
        pageSize: 15,
        total: 0,
        showTotal: (total, range) => {
          return `共 ${total},${range[0]}/${range[1]}`
        },
      },
      machine_room_event: (record) => {
        return {
          onDblclick: (event) => {
            this.machine_room_dblclick_row(record);
          },
        };
      },
      show_machine:false,
      machine_qs:{
        _id:"",
        name:"",
        aname:"",
        jfbm:"",
        bh:"",
        wz:"",
        type:"",
        status:"",
      },
      select_room_levels:[],
      machine_data:[],
      machine_data_sysy:0,
      machine_columns: [
        {
          title: '设备名称',
          dataIndex: 'name',
          align: 'center',
          width: '120px',
          ellipsis: true,
        },
        {
          title: '设备别名',
          dataIndex: 'aname',
          align: 'center',
          width: '210px',
          ellipsis: true,
        },
        {
          title: '机房编号',
          dataIndex: 'jfbm',
          align: 'center',
          width: '60px',
          ellipsis: true,
        },
        {
          title: '设备编号',
          dataIndex: 'bh',
          align: 'center',
          width: '140px',
          ellipsis: true,
        },
        {
          title: '管理者',
          dataIndex: 'glz',
          align: 'center',
          width: '80px',
        },
        {
          title: '使用者',
          dataIndex: 'syz',
          align: 'center',
          width: '140px',
        },
        {
            title: '设备类型',
            dataIndex: 'type',
            align: 'center',
            width: '60px',
        },
        {
            title: '设备状态',
            dataIndex: 'status',
            align: 'center',
            width: '60px',
        },
        {
            title: '存储剩余TB',
            width: 80,
            dataIndex: 'sysy',
            align: 'center'
        },
        {
            title: '操作',
            width: 60,
            dataIndex: 'operation',
            align: 'center'
        },
      ],
      net_columns: [
        {
        title: '网络名',
        dataIndex: 'net',
        align: 'center',
        width: '120px',
        ellipsis: true,
        },
        {
        title: '网络带宽',
        dataIndex: 'netdk',
        align: 'center',
        width: '210px',
        ellipsis: true,
        },
        {
        title: '线缆类型',
        dataIndex: 'netlt',
        align: 'center',
        width: '60px',
        ellipsis: true,
        },
        {
        title: '端口类型',
        dataIndex: 'netpt',
        align: 'center',
        width: '140px',
        ellipsis: true,
        },
        {
        title: '本端端口',
        dataIndex: 'ap',
        align: 'center',
        width: '170px',
        ellipsis: true,
        },
        {
        title: '对端设备',
        dataIndex: 'bname',
        align: 'center',
        width: '140px',
        },
        {
            title: '对端端口',
            dataIndex: 'bp',
            align: 'center',
            width: '140px',
        },
      ],
      machine_pagination: {
        current: 1,
        size: 'small',
        pageSize: 50,
        total: 0,
        pageSizeOptions:['10', '50', '100', '500', '1000', '3000'],
        showTotal: (total, range) => {
          return `共 ${total},${range[0]}/${range[1]}`
        },
      },
      machine_tab_activeKey:"11",
    }
  },
  components: {
    add_machine: defineAsyncComponent(() => import("./machine/add_machine.vue")),
    edit_machine_rome_person: defineAsyncComponent(() => import("./machine/edit_machine_rome_person.vue")),
    badd_machine: defineAsyncComponent(() => import("./machine/badd_machine.vue")),
    add_machine_rome: defineAsyncComponent(() => import("./machine/add_machine_rome.vue")),
  },
  beforeUnmount() {
    this.$mitt.off('add_machine_rome_drawer_result');
    this.$mitt.off('add_machine_drawer_result');
    this.$mitt.off('badd_machine_drawer_result');
    this.$mitt.off('edit_machine_rome_person_drawer_result');
  },
  mounted() {
    this.$mitt.on('add_machine_rome_drawer_result', _result => {
      if(_result){
        console.log(_result)
        this.add_machine_room_core(_result);
      }
    });
    this.$mitt.on('add_machine_drawer_result', _result => {
      if(_result){
        console.log(_result)
        this.add_machine_core(_result);
      }
    });
    this.$mitt.on('badd_machine_drawer_result', _result => {
      if(_result){
        console.log(_result)
        this.add_machine_core(_result)
      }
    });
    this.$mitt.on('edit_machine_rome_person_drawer_result', _result => {
      if(_result){
        this.search_machine_room();
      }
    });
    this.search_machine_room()
    this.get_user_levels()
  },
  methods: {
    async get_user_levels(){
      let qs_result = await this.$apis.get_room_level({
        uid:this.$store?.state?.user?.id,
      })
      if (qs_result) {
        this.$store.state.user_machine_room_levels=qs_result
      }
      if(this.$store?.state?.user?.id=='super'){
        this.select_room_levels=[true,true,true,true] 
      }
      
      console.log(qs_result)
    },
    check_machine_room_qx(record,index){
      let select_room_levels=[true,true,true,true] 
      if(this.$store?.state?.user?.id=='super'){
        this.select_room_levels=[true,true,true,true] 
      }
      else{
        this.select_room_levels=this.$common_apis.Get_machine_room_level(record["_id"])
      }
      if(select_room_levels?.length==4 && select_room_levels[index]===true){
        return true
      }
      else{
        return false
      }

    },
    async search_machine_room() {
      this.search_machine_room_core();
    },
    async search_machine_room_core() {
      this.$Loading.start();
      this.machine_room_data =[]
      let new_search_qs = JSON.parse(JSON.stringify(this.machine_room_qs))
      new_search_qs.pagenum = this.machine_room_pagination.current
      new_search_qs.pagesize = this.machine_room_pagination.pageSize
      let qs_result = await this.$apis.get_machine_room(new_search_qs)
      if (qs_result) {
          this.machine_room_pagination.total = qs_result?.page?.count
          let room_data=qs_result?.data
          room_data.sort((a,b)=>{
            let ajfbmN=a.jfbm.replace("J","")-0
            let bjfbmN=b.jfbm.replace("J","")-0
            let ajfbm2N=a.jfbm2-0
            let bjfbm2N=b.jfbm2-0
            if(ajfbmN==bjfbmN){
              return ajfbm2N-bjfbm2N
            }
            return ajfbmN-bjfbmN
          })
          this.machine_room_data =room_data
          this.machine_room_machine_count=0
          room_data.forEach(element => {
            this.machine_room_machine_count=element.num-0+this.machine_room_machine_count
          });
      }
      this.$Loading.done();
    },
    machine_room_pagination_change(pagination){
      this.machine_room_pagination.current = pagination.current
      if (pagination.pageSize != this.machine_room_pagination.pageSize) {
        this.machine_room_pagination.pageSize = pagination.pageSize
        this.machine_room_pagination.current = 1
      }
      this.search_machine_room_core()
    },
    machine_room_xz_change(){
      this.search_machine_room_core();
    },
    machine_room_dblclick_row(record){
      this.machine_qs.jfbm=record.jfbm
      this.machine_qs.jfbm2=record.jfbm2
      this.tab_activeKey="2"
      this.show_machine=true
      if(this.$store?.state?.user?.id=='super'){
        this.select_room_levels=[true,true,true,true] 
      }
      else{
        this.select_room_levels=this.$common_apis.Get_machine_room_level(record["_id"])
      }
      this.search_machine()
    },
    tab_change(activeKey){
      if(activeKey==1){
        this.show_machine=false
      }
    },
    add_machine_room(){
      this.$mitt.emit('add_machine_rome_drawer',undefined)
    },
    edit_machine_room(record){
      this.$mitt.emit('add_machine_rome_drawer',record)
    },
    edit_machine_room_person(record){
      this.$mitt.emit('edit_machine_rome_person_drawer',{
        role:this.role_id,
        record:record
      })
    },  
    async add_machine_room_core(_machine_room){
      this.$Loading.start();
      this.$apis.add_machine_room(_machine_room).then(result => {
        this.search_machine_room()
      });
      this.$Loading.done();
    },
    show_machine_room_tp(record){
      if(record?.ttt){
        let _href = `${window.server_url}/change/show_ttt_file?file=${record?.ttt}`
        window.open(_href, '_blank');
      }
      else{
        this.$message.info("拓扑图不存在!")
      }
    },
    async search_machine() {
      this.search_machine_core();
    },
    async search_machine_core() {
      this.$Loading.start();
      this.machine_data =[]
      let new_search_qs = JSON.parse(JSON.stringify(this.machine_qs))
      new_search_qs.pagenum = this.machine_pagination.current
      new_search_qs.pagesize = this.machine_pagination.pageSize
      let qs_result = await this.$apis.get_machine(new_search_qs)
      if (qs_result) {
        this.machine_pagination.total = qs_result?.page?.count
        this.machine_data_sysy=0
        let machine_data=qs_result?.data
        machine_data.forEach(element => {
          if(element?.cc>=0 && element?.ccsy>=0){
            element.sysy=(element?.cc-element?.ccsy).toFixed(1)-0
          }
          else{
            element.sysy=0
          }
          this.machine_data_sysy=this.machine_data_sysy+element.sysy
        });
        this.machine_data_sysy=this.machine_data_sysy.toFixed(1)-0
        this.machine_data = machine_data
      }
      this.$Loading.done();
    },
    machine_type_change() {
      this.search_machine_core();
    },
    machine_status_change() {
      this.search_machine_core();
    },
    machine_jfbm_change() {
      this.search_machine_core();
    },
    machine_jfbm2_change() {
      this.search_machine_core();
    },
    
    machine_pagination_change(pagination){
      this.machine_pagination.current = pagination.current
      if (pagination.pageSize != this.machine_pagination.pageSize) {
        this.machine_pagination.pageSize = pagination.pageSize
        this.machine_pagination.current = 1
      }
      this.search_machine_core()
    },
    add_machine(){
      this.$mitt.emit('add_machine_drawer',{
        jfbm: this.machine_qs.jfbm,
        jfbm2: this.machine_qs.jfbm2
      })
    },
    async add_machine_core(_machine){
      this.$Loading.start();
      let _machines=[]
      if(Array.isArray(_machine)){
        _machines=_machine
      }
      else{
        _machines=[_machine]
      }
      for (let i = 0; i < _machines.length; i++) {
        let one_machine = _machines[i];
        await this.$apis.add_machine(one_machine)
      }
      this.search_machine()
      this.$Loading.done();
    },
    edit_machine(record){
      let new_val=JSON.parse(JSON.stringify(record))
      delete new_val["__v"]
      delete new_val["nets"]
      this.$mitt.emit('add_machine_drawer',new_val)
    },
    async delete_machine(record){
      this.$Loading.start();
      let qs_result = await this.$apis.delete_machine({
        id:record["_id"]
      })
      if (qs_result) {
        this.search_machine_core()
      }
      this.$Loading.done();
    },
    async clear_machine(){
      this.$Loading.start();
      let qs_result = await this.$apis.delete_machines({
        jfbm: this.machine_qs.jfbm,
        jfbm2: this.machine_qs.jfbm2
      })
      if (qs_result) {
        this.search_machine_core()
      }
      this.$Loading.done();
      
    },
    badd_machine(){
      this.$refs.excle_input.click()
    },
    async get_excle(event){
      let selectedFile = event.target.files[0]
      let workbook=await this.$common_apis.read_xml_to_workbook(selectedFile)
      document.getElementById('excle_input').value= ''; 
      let  SheetName="";
      if(Array.isArray(workbook?.SheetNames)){
        if(workbook?.SheetNames?.length){
          SheetName=workbook?.SheetNames[0]
        }
      }
      if(!SheetName){
        this.$message.info("选择的excle没有sheet")
        return
      }
      let rows=await this.$common_apis.read_workbook(workbook,SheetName)
      if(rows?.length){
        let new_rows=this.$common_apis.excle_col_convert(rows)
        this.$mitt.emit('badd_machine_drawer',{
          rows:new_rows,
          keys:{
            jfbm: this.machine_qs.jfbm,
            jfbm2: this.machine_qs.jfbm2
          }
        })
      }
    },
  },
}
</script>